var partition = function (head, x) {
    let dHead = new ListNode(0, head)
    let h = head,
        n = 0,
        arr = [],
        res = []
    while (h) {
        arr[n++] = h.val
        h = h.next
    }
    let j = 0;
    for (let i = 0; i < n; i++) {
        if (arr[i] < x) {
            res[j++] = arr[i]
        }

    }
    for (let i = 0; i < n; i++) {
        if (arr[i] >= x) {
            res[j++] = arr[i]
        }
    }
    h = head
    j = 0
    while (h) {
        h.val = res[j++]
        h = h.next
    }
    return dHead.next

};